﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Maticsoft.Common;
using DQYT.HTDZ.DBUtility;
using DQYT.HTDZ.BusinessService;
using System.Xml;
using System.Text;
using System.Drawing;
using DQYT.HTDZ.Common;
using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;
using Maticsoft.DBUtility;
using System.Data.OracleClient;

namespace DQYT.HTDZ.Web.Views.Report
{
    public partial class Report : System.Web.UI.Page
    {
        private BDDATESOURCEModel bddatesoursemodel;
        private BDPULLModel bdpullmodel;
        private BDPOVERMACHINEModel djmodel;
        private BDVALUEModel valuemodel;

        private BDDATESOURSEBLL datesoursedll;
        private BDPULLBLL pullbll;
        private BDPOVERMACHINEBLL djbll;
        private BDVALUEBLL valuebll;
        private string wellid;

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                //获取井号、检测日期和诊断时间
                //if(Request.QueryString["wellid"]==null)
                //{
                //    wellid = "晋105-8";
                //}
                //if (Request.QueryString["jcrq"]==null)
                //{
                //    this.txt_JCRQ.Text = "2012/1/3 0:00:00";
                //}
                //if (Request.QueryString["zdsj"]==null)
                //{
                //    this.txt_ZDSJ.Text = "2014/1/13 10:59:15";
                //}
                wellid = Request.QueryString["wellid"];//"晋105-33X"; 
                this.txt_JCRQ.Text = Request.QueryString["jcrq"];//"2012-1-3 00:00:00";
                this.txt_ZDSJ.Text = Request.QueryString["zdsj"];//"2013-12-8 10:10:41"; 

                this.txt_WELLID.Text = wellid;
               // this.Chart_HYGGL.ForeColor = Color.Red;
                this.Chart_HYGGL.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_HYGGL.Series[0].Color = Color.DarkBlue;


                this.Chart_ADL.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_ADL.Series[0].Color = Color.DarkBlue;

                 this.Chart_ADY.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_ADY.Series[0].Color = Color.DarkBlue;

             
                this.Chart_HGLYS.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_HGLYS.Series[0].Color = Color.DarkBlue;

                this.Chart_HSZGL.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_HSZGL.Series[0].Color = Color.DarkBlue;

                this.Chart_HWGGL.ChartAreas[0].AxisX.Interval = 90;
                this.Chart_HWGGL.Series[0].Color = Color.DarkBlue;


                this.Chart_SGT.Series[0].Color = Color.DarkBlue;


                //初始化
                init();
            }
           
        }
        /// <summary>
        /// 初始化
        /// </summary>
        protected void init()
        {
            //根据井号和检测日期获得基础数据表
            BDCjsjFunc bdcjsjfun = new BDCjsjFunc();
            bddatesoursemodel = bdcjsjfun.getdatesousemodel(this.txt_WELLID.Text, this.txt_JCRQ.Text);
            //获得特征值
            BDValueFunc valueFun = new BDValueFunc();
            valuemodel = valueFun.getValueModel(this.txt_WELLID.Text, this.txt_JCRQ.Text);
            //根据抽油机ID获得抽油机相关信息 
            //根据电机ID获得电机相关信息
            initChart();
            initdata();

        }
        /// <summary>
        /// 初始化chart
        /// </summary>
        protected void initChart()
        {
            BDCjsjFunc cjsjFunc = new BDCjsjFunc();
            decimal id = bddatesoursemodel.ID;
            string strSql = "select CJSJ FROM BDDATESOURSE  where ID='" + id + "'";
            BDDATESOURSEBLL bll = new BDDATESOURSEBLL();
            DataTable drawTb = bll.GetList_SQL(strSql).Tables[0];//获得一条记录
            byte[] btCjsj = (byte[])drawTb.Rows[0]["CJSJ"];
            List<CJSJModel> cjsjModels = BinarySerializer.DeserializeObject<List<CJSJModel>>(btCjsj);
     
            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "ADY");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv2 = new DataView(drawTb);//收集数据集
            this.Chart_ADY.Series[0].Points.DataBindXY(dv2, "X", dv2, "ADY");

            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "ADL");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv3 = new DataView(drawTb);//收集数据集
            this.Chart_ADL.Series[0].Points.DataBindXY(dv3, "X", dv3, "ADL");

            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "HYGGL");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv4 = new DataView(drawTb);//收集数据集
            this.Chart_HYGGL.Series[0].Points.DataBindXY(dv4, "X", dv4, "HYGGL");

            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "HWGGL");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv5 = new DataView(drawTb);//收集数据集
            this.Chart_HWGGL.Series[0].Points.DataBindXY(dv5, "X", dv5, "HWGGL");

            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "HSZGL");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv6 = new DataView(drawTb);//收集数据集
            this.Chart_HSZGL.Series[0].Points.DataBindXY(dv6, "X", dv6, "HSZGL");

            drawTb = cjsjFunc.listCJSJModelToDataTable(cjsjModels, "HGLYS");//提取欲描图参数
            drawTb.Columns.Add("X", typeof(System.Double));
            drawTb = numToAngle(drawTb);
            DataView dv9 = new DataView(drawTb);//收集数据集
            this.Chart_HGLYS.Series[0].Points.DataBindXY(dv9, "X", dv9, "HGLYS");

            drawTb = cjsjFunc.getSGT(cjsjModels);//提取欲描图参数
            //drawTb.Columns.Add("LTWY", typeof(System.Double));
            //drawTb.Columns.Add("XDZH", typeof(System.Double));
            DataView dv8 = new DataView(drawTb);//收集数据集
            this.Chart_SGT.Series[0].Points.DataBindXY(dv8, "LTWY", dv8, "XDZH");

        }
        
        /// <summary>
        /// 初始化界面数据栏数据
        /// </summary>
        public void initdata()
        {
            
            this.txt_CC.Text =(valuemodel.CYJCC==9999999)? " ": Math.Round((double)valuemodel.CYJCC, 2).ToString();
            this.txt_CCI.Text = (valuemodel.CYJCCI == 9999999) ? " " : Math.Round((double)valuemodel.CYJCCI, 2).ToString();
            this.txt_PHKZL1.Text = (valuemodel.PHKZL1 == 9999999) ? " " : Math.Round((double)valuemodel.PHKZL1, 2).ToString();
            this.txt_PHDWZ1.Text = (valuemodel.PHDWZ1 == 9999999) ? " " : valuemodel.PHDWZ1.ToString();

            this.txt_SXDLMAX.Text = (valuemodel.SXDLMAX == 9999999) ? " " : Math.Round((double)valuemodel.SXDLMAX, 2).ToString();
            this.txt_XXDLMAX.Text = (valuemodel.XXDLMAX == 9999999) ? " " : Math.Round((double)valuemodel.XXDLMAX, 2).ToString();
            this.txt_DDZDZPHD.Text = (valuemodel.DDZDZPHD == 9999999) ? " " : Math.Round((double)valuemodel.DDZDZPHD, 2).ToString();
            this.txt_SXYGPJZ.Text = (valuemodel.SXYGPJZ == 9999999) ? " " : Math.Round((double)valuemodel.SXYGPJZ, 2).ToString();
            this.txt_XXYGPJZ.Text = (valuemodel.XXYGPJZ == 9999999) ? " " : Math.Round((double)valuemodel.XXYGPJZ, 2).ToString();
            this.txt_YGPJZPHD.Text = (valuemodel.YGPJZPHD == 9999999) ? " " : Math.Round((double)valuemodel.YGPJZPHD, 2).ToString();
            this.txt_SXYGMAX.Text = (valuemodel.SXYGMAX == 9999999) ? " " : Math.Round((double)valuemodel.SXYGMAX, 2).ToString();
            this.txt_XXYGMAX.Text = (valuemodel.XXYGMAX == 9999999) ? " " : Math.Round((double)valuemodel.XXYGMAX, 2).ToString();
            this.txt_YGZDZPHD.Text = (valuemodel.YGZDZPHD == 9999999) ? " " : Math.Round((double)valuemodel.YGZDZPHD, 2).ToString();
            this.txt_RWGNH.Text = (valuemodel.RWGNH == 9999999) ? " " : Math.Round((double)valuemodel.RWGNH, 2).ToString();
            this.txt_RYGZNH.Text = (valuemodel.RYGZNH == 9999999) ? " " : Math.Round((double)valuemodel.RYGZNH, 2).ToString();
            this.txt_RYGFNH.Text = (valuemodel.RYGFNH == 9999999) ? " " : Math.Round((double)valuemodel.RYGFNH, 2).ToString();
            this.txt_YGFZL.Text = (valuemodel.YGFZL == 9999999) ? " " : Math.Round((double)valuemodel.YGFZL, 2).ToString();
            this.txt_YGPZL.Text = (valuemodel.YGPZL == 9999999) ? " " : Math.Round((double)valuemodel.YGPZL, 2).ToString();


            //this.txt_BJ.Text = valuemodel.BJ.ToString();
            //this.txt_CYL.Text = valuemodel.RCYL.ToString();
            //this.txt_HS.Text = valuemodel.HS.ToString();
            //this.txt_DYM.Text = valuemodel.DYM.ToString();
            //this.txt_CMD.Text = valuemodel.CMD.ToString();
            //this.txt_BX.Text = valuemodel.BX.ToString();
            //this.txt_YY.Text = valuemodel.YY.ToString();
            //this.txt_TY.Text = valuemodel.TY.ToString();

            //初始化诊断表中的数据
            string sqlstr = "select * from BDTEPZDJY WHERE ZDSJ=to_date( '" + this.txt_ZDSJ.Text + "','yyyy/MM/dd HH24:mi:ss ') and WELLID='" + this.txt_WELLID.Text + "'";
            DataTable zdjyTb = DbHelperOra.Query_Table(sqlstr);
            this.txt_ZDSJ.Text = zdjyTb.Rows[0]["ZDSJ"].ToString();//诊断时间
            this.txt_ZDR.Text = zdjyTb.Rows[0]["ZDR"].ToString();//诊断时间
            this.txt_ZDJY.Text = zdjyTb.Rows[0]["ZDJY"].ToString();//诊断时间
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_update_Click(object sender, EventArgs e)
        {
            string sqlstr = "update  BDTEPZDJY set ZDJY='" + this.txt_ZDJY.Text + "' WHERE ZDSJ=to_date( '" + this.txt_ZDSJ.Text + "','yyyy/MM/dd HH24:mi:ss ') and WELLID='" + this.txt_WELLID.Text + "'";
            DbHelperOra.ExecuteSql(sqlstr);
            init();
           
        }
        /// <summary>
        /// 将横坐标中的点转换成度数
        /// </summary>
        /// <param name="drawTb"></param>
        /// <returns></returns>
        protected DataTable numToAngle(DataTable drawTb)
        {
            int len = drawTb.Rows.Count;
            DataTable newTb = drawTb.Clone();
            foreach (DataRow row in drawTb.Rows)
            {

                newTb.ImportRow(row);

            }


            for (int i = 0; i < len; i++)
            {
                double xValue = 360.0 / len * (i + 1);
                newTb.Rows[i]["X"] = xValue;
            }
            return newTb;  
        }
       
    }
}
